package plg.grupo1.Lexico.StateMachineHierarchy;

public class State0 implements State{

    private static State0 INSTANCE = null;    
	private State0(){}
	
    private synchronized static void createInstance() {
        if (INSTANCE == null) INSTANCE = new State0();
    }
    
    public static State0 getInstance() {
        if (INSTANCE == null) createInstance();
        return INSTANCE;
    }
    
	public void goNext(){
		
		if(Contexto.isEof()){
			Contexto.setCurrentState(State9.getInstance());
		}
		else{	
			
			char c = Contexto.getCharAndMoveToNext();//A
			Contexto.appendToLexema(c);//B
			
			if(c=='{') 
				Contexto.setCurrentState(State1.getInstance()); 
			else if(c=='}') 
				Contexto.setCurrentState(State2.getInstance());
			else if(c=='\\'){//no apilamos la primera \
				Contexto.removeLastCharFromLexema();
				Contexto.setCurrentState(State3.getInstance());
			}
			else if(c=='\n'){
				Contexto.removeLastCharFromLexema();
				Contexto.increaseLine(); //L
			}
			else if("\0\r\t".indexOf(c)!=-1)
				Contexto.removeLastCharFromLexema();			
			else 
				Contexto.setCurrentState(State14.getInstance());
		}
	}
}